import { createRouter, RouteRecordRaw, createWebHistory } from 'vue-router'

import { NprogressStart, Nprogressclose} from '@/utils/nprogress'
import Index from '../views/index.vue'

const routes: Array<RouteRecordRaw> = [
    {
        path: '/',
        name: 'index',
        meta: {
          title: '首页'
        },
        component: Index
    },
    {
        path: '/home',
        name: 'home',
        meta: {
          title: 'home页'
        },
        component: () => import('@/views/home.vue')
    },
    {
        path: '/:catchAll(.*)',
        name: '404',
        meta: {
          title: '404'
        },
        component: () => import('@/views/status/404.vue')
    }
]


const router = createRouter({
    history: createWebHistory(),
    routes
})

// 路由拦截器
router.beforeEach((from, to, next) => {
    NprogressStart()
    next()
})

router.afterEach(() => {
    Nprogressclose()
})

export default router